﻿/*----------------------------------------------------------------
//  <copyright file="FunctionCacheRefreshEvent.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2023-09-17 18:03</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud
{
    #region "功能信息缓存刷新事件源"
    /// <summary>
    /// 功能信息缓存刷新事件源
    /// </summary>
    public class FunctionCacheRefreshEventData : EventDataBase
    { }
    #endregion

    #region "功能信息缓存刷新事件处理器"
    /// <summary>
    /// 功能信息缓存刷新事件处理器
    /// </summary>
    public class FunctionCacheRefreshEventHandler : EventHandlerBase<FunctionCacheRefreshEventData>
    {
        //字段
        private readonly IServiceProvider _provider;

        #region "构造函数"
        #region "初始化一个功能信息缓存刷新事件处理器的新实例"
        /// <summary>
        /// 初始化一个功能信息缓存刷新事件处理器 <see cref="FunctionCacheRefreshEventHandler"/> 的新实例
        /// </summary>
        /// <param name="provider"></param>
        public FunctionCacheRefreshEventHandler(IServiceProvider provider)
        {
            _provider = provider;
        }
        #endregion

        #endregion

        #region "方法"
        #region "事件处理"
        /// <summary>
        /// 事件处理
        /// </summary>
        /// <param name="eventData">事件源数据</param>
        /// <param name="provider">服务提供者</param>
        public override void Handle(FunctionCacheRefreshEventData eventData, IServiceProvider provider)
        {
            if (!_provider.InHttpRequest())
            {
                return;
            }
            IFunctionHandler functionHandler = _provider.GetService<IFunctionHandler>();
            functionHandler.RefreshCache();
        }
        #endregion

        #endregion

    }
    #endregion

}
